﻿using System;
using log4net;
using log4net.Config;

namespace WI.CandidateManager.Common.Logging
{
    /// <summary>
    /// Class Logger
    /// </summary>
    internal class Logger : ILogger
    {
        #region Fields
        private readonly ILog log;
        #endregion

        #region Constructors
        static Logger()
        {
            XmlConfigurator.Configure();
        }

        public Logger(Type type)
        {
            log = LogManager.GetLogger(type);
        }
        #endregion

        #region Methods
        /// <summary>
        /// Infoes the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        void ILogger.Info(object message, Exception exception)
        {
            if (log.IsInfoEnabled)
            {
                log.Info(message, exception);
            }
        }

        /// <summary>
        /// Warns the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        void ILogger.Warn(object message, Exception exception)
        {
            if (log.IsWarnEnabled)
            {
                log.Warn(message, exception);
            }
        }

        /// <summary>
        /// Errors the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        void ILogger.Error(object message, Exception exception)
        {
            if (log.IsErrorEnabled)
            {
                log.Error(message, exception);
            }
        }

        /// <summary>
        /// Fatals the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        void ILogger.Fatal(object message, Exception exception)
        {
            if (log.IsFatalEnabled)
            {
                log.Fatal(message, exception);
            }
        }
        #endregion
    }
}
